﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimplePoker.Main
{
    class Program
    {
        static void Main(string[] args)
        {
            var player1 = new BasicPlayer("Basic Player");
            var player2 = new BetterThanBasicPlayer("Better Than Basic Player");

            string winnerName = GetWinner(player1, player2);

            Console.WriteLine("Winner: " + winnerName);
            Console.Read();

        }

        private static string GetWinner(PlayerBase player1, PlayerBase player2)
        {
            int p1Wins = 0;
            int SIMULATIONS = 9999;

            for (int i = 0; i < SIMULATIONS; i++)
            {
                int flip = (new int[] { 1, 2 }).OrderBy(x => Guid.NewGuid()).First();
                player1.ChipCount = 1000;
                player2.ChipCount = 1000;
                Tournament t;

                if (flip == 1)
                    t = new Tournament(player1, player2);
                else
                    t = new Tournament(player2, player1);

                var winner = t.GetWinner();

                if (winner.Name == player1.Name)
                    p1Wins++;

                Console.Clear();
                Console.WriteLine("{0} wins: {1}/{2} ",player1.Name, p1Wins, i);
            }

            if (p1Wins > (SIMULATIONS / 2))
                return player1.Name;
            else
                return player2.Name;
        }


    }

}
